package com.tz.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Created by heziqian on 2016/10/21.
 */
@Entity
@Table(name = "ONLINE_ORDER")
public class Order implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8906198721411425227L;
	private Long orderId;
	private String orderNum;
	private Date createDate;
	private Set<OrderItem> items;
	private User user;
	private Address address;
	private String orderStatus;
	public Order() {
		super();
	}
	public Order(String orderNum, Date createDate, Set<OrderItem> items,
			User user, Address address, String orderStatus) {
		super();
		this.orderNum = orderNum;
		this.createDate = createDate;
		this.items = items;
		this.user = user;
		this.address = address;
		this.orderStatus = orderStatus;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "order_id")
	@SequenceGenerator(name = "order_id", sequenceName = "online_order_id")
	public Long getOrderId() {
		return orderId;
	}
	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}
	
	@Column
	public String getOrderNum() {
		return orderNum;
	}
	public void setOrderNum(String orderNum) {
		this.orderNum = orderNum;
	}
	
	@Column(nullable=false)
	@Temporal(TemporalType.DATE)
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	@OneToMany(mappedBy="order",cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	//@OneToMany(mappedBy="order")
	public Set<OrderItem> getItems() {
		return items;
	}
	
	public void setItems(Set<OrderItem> items) {
		this.items = items;
	}
	
	@ManyToOne
	@JoinColumn(name="user_id")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	@ManyToOne
	@JoinColumn(name="address_id")
	public Address getAddress() {
		return address;
	}
	public void setAddress(Address address) {
		this.address = address;
	}
	
	@Column
	public String getOrderStatus() {
		return orderStatus;
	}
	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}
	
	
}
